//
//  GBInterMaster_PackUtil.h
//  NetworkTest
//
//  Created by xiaosi on 16/7/26.
//  Copyright © 2016年 xiaosi. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "GCDAsyncSocket.h"
#import "GBInterMaster_Util.h"
#import "GBInterMaster_NetData.h"
#import "GBInterMaster_APPLogic_CRC16.h"
#import "GBInterMaster_LogicLauncher.h"

 static const int PTCP_V10_VALUE_BEGIN_1 = 0xC6;
 static const int PTCP_V10_VALUE_BEGIN_2 =  0x3E;
 static const int PTCP_V10_VALUE_BEGIN_3  = 0x07;
 static const int PTCP_V10_VALUE_BEGIN_4 =  0x6A;
 static const int PTCP_V10_VALUE_PROTOCAL_VER =  0x10;

 static const int NETBYTE_LIMIT_MAX_LENGTH  = 10240;
 static const int PTCP_V10_LEN_BEGIN_TAG  = 4;
 static const int PTCP_V10_LEN_PROTOCAL_VER  = 1;
 static const int PTCP_V10_LEN_DLG_LIFE_CYCLE  = 1;
 static const int PTCP_V10_LEN_CMD_TYPE  = 1;
 static const int PTCP_V10_LEN_OBLIGATE1  = 1;
 static const int PTCP_V10_LEN_LENGTH =  2;
 static const int PTCP_V10_LEN_CMD  = 2;
 static const int PTCP_V10_LEN_TIMESTAMP =  7;
 static const int PTCP_V10_LEN_OBLIGATE2 =  1;
 static const int PTCP_V10_LEN_MSG_ID =  2;
 static const int PTCP_V10_LEN_CONN_ID =  2;
 static const int PTCP_V10_LEN_CRC32 =  4;
 static const int PTCP_V10_LEN_CRC16 =  2;
 static const int PTCP_V10_LEN_FIXED =  26;


typedef enum _PTCP {
    PTCP_OK = 0x0, //正确
    PTCP_ERR = 0xFF, //错误
    PTCP_ERR_NOT_RECV_OVER = 0x10, //数据未接收完毕
    PTCP_ERR_OUT_OF_MEMORY = 0x11, //内存不足
    PTCP_ERR_OUT_OF_RANGE = 0x12, //数据报长度超过最大长度
    PTCP_ERR_LESS_THAN_FIXED = 0x20, //数据小于协议数据最小字节
    PTCP_ERR_INVALID_PACKAGE = 0x13, //非法的数据报
    PTCP_ERR_INVALID_BEGIN_TAG = 0x14, //非法的起始标记
    PTCP_ERR_INVALID_END_TAG = 0x15, //非法的结束标记
    PTCP_ERR_INVALID_CHECKVAL = 0x16, //非法的校验值
    PTCP_ERR_INVALID_PROT_VER = 0x17, //非法的协议版本
    PTCP_ERR_INVALID_DATAFMT_VER = 0x18, //非法的数据格式版本
    PTCP_ERR_TIMEOUT = 0x19, //发送或者接收的数据超时
    PTCP_ERR_INVALID_CMD_TYPE = 0x1A, //非法的指令类型
} PTCP;


@interface GBInterMaster_PackUtil : NSObject

+ (PTCP) pack10:(GBInterMaster_NetData*)data;

+ (PTCP) pack10_udp:(GBInterMaster_NetData*)data;

+ (PTCP) unpack10:(GBInterMaster_NetData*)data outData:(NSData*)bytes;

@end
